<?php
/**
 * ===============================================
 * 版权所有 2019-2050 青岛铁锤科技有限公司，并保留所有权利。
 * 网站地址: http://www.huaxianling.com
 * ===============================================
 * Author: Happy dong
 * Created Time: 2019-06-25 10:09
 * Modified Time: 2019-06-25 10:09
 * Version: 2.0
 */

namespace App\Modules\Employee\Controllers;

use App\Exceptions\NotFoundException;
use App\Lib\Facades\FLAuth;
use App\Lib\Utilities;
use App\Modules\Employee\Services\DynamicService;
use App\Modules\Employee\Validators\DynamicControllerValidator;
use Flower\Core\Http\BaseController;
use Flower\Core\Http\Request;

/**
 * Class DynamicController 理发师动态
 * @package App\Modules\Employee\Controllers
 * Author: Happy dong
 * Created Time: 2019-06-25 10:28
 */
class DynamicController extends BaseController
{
    private $dynamicService;

    public function __construct(DynamicService $dynamicService)
    {
        $this->dynamicService = $dynamicService;
    }



	public function getRules()
	{
		return DynamicControllerValidator::validator();
	}


	/**
	 * 获取剪发师动态列表
	 * @param Request $request
	 * @return mixed
	 * @throws \Flower\Core\Repository\Exceptions\RepositoryException
	 * @author Happy dong
	 * @modifiedTime 2019-08-09 17:05
	 */
    public function getDynamicList(Request $request)
    {
        $store_id = $request->input('store_id');
        $list = $this->dynamicService->getDynamicList(FLAuth::id(),$store_id,$request->page_size);
        $list = Utilities::dealPage($list);
        return $this->display($list);
    }




	/**
	 * 新增动态App
	 * @param Request $request
	 * @return mixed
	 * @author Happy dong
	 * @modifiedTime 2019-08-09 17:05
	 */
    public function addDynamic(Request $request)
    {
        $store_id = $request->input('store_id');
        $res = $this->dynamicService->addNewDynamic(FLAuth::id(),$store_id,$request->detail,$request->image,$request->video);
        if (!$res) return $this->error('新增动态失败');
        return $this->success('新增动态成功');
    }

	/**
	 * 编辑动态
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 * @author Happy dong
	 * @modifiedTime 2019-08-09 17:05
	 */
	public function editDynamic(Request $request)
	{
		if(!$request->has('detail') || !$request->has('dynamic_id')){
			throw new NotFoundException(['msg'=>'参数缺失']);
		}
		$res = $this->dynamicService->editDynamic(FLAuth::id(),$request->detail,$request->image,$request->video,$request->dynamic_id);
		if (!$res) return $this->error('编辑动态失败');
		return $this->success('编辑动态成功');
	}

	/**
	 * 理发师删除动态App
	 * @param Request $request
	 * @return mixed
	 * @throws \App\Exceptions\NotFoundException
	 * @author Happy dong
	 * @modifiedTime 2019-08-09 17:05
	 */
    public function delDynamic(Request $request)
    {
        $res = $this->dynamicService->deleteDynamic(FLAuth::id(),$request->dynamic_id);
        if (!$res) return $this->error('理发师动态删除失败');
        return $this->success('理发师动态删除成功！');
    }


    /*
     * 小程序获取视频动态
     */
    public function getVideoDynamicList(Request $request)
    {
        $dynamic_list = $this->dynamicService->getVideoDynamicList($request->all());
        return $this->display($dynamic_list, '查询成功');
    }

    /*
     * 动态点赞
     */
    public function dynamicLike(Request $request)
    {
        $this->dynamicService->dynamicLike($request->all());
        return $this->success('操作成功');
    }

    /*
     * 获取某店下所有理发师发的动态
     */
    public function getStoreDynamicList(Request $request)
    {
        $store_id = $request->input('store_id');
        $pageSize = $request->input('pageSize',10);
        $list = $this->dynamicService->getStoreDynamicList($store_id,$pageSize);
        return $this->display($list,'查询成功');
    }
}